home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / System / Felix 1.1 / cdev class.c next >
Encoding:
C/C++ Source or Header  |  1994-04-16  |  3.7 KB  |  282 lines  |  [TEXT/KAHL]

  1.  
  2. /*
  3.  *  cdev class.c - standard cdev object
  4.  *
  5.  *  Copyright (c) 1991 Symantec Corporation.  All rights reserved.
  6.  *
  7.  */
  8.  
  9. #include "cdev.h"
  10.  
  11. pascal long _main(short, short, short, short, EventRecord *, cdev *, WindowPeek);
  12.  
  13. /*
  14.  *  _main - cdev entry point
  15.  *
  16.  *  The correct value for A4 must be in A0 on entry.  When built as
  17.  *  an application (for debugging purposes), "cdev runner" calls this
  18.  *  routine with A0=0; this signals us NOT to try to unload A4-based
  19.  *  segments.  When built as a cdev, "cdev stub" loads A0 with the
  20.  *  address of the cdev before calling this routine.  (Note that this
  21.  *  file MUST be in the same segment as "cdev stub.c".)
  22.  *
  23.  */
  24.  
  25. pascal long
  26. _main(short msg, short item, short nitems, short id, EventRecord *event, cdev *value, WindowPeek dp)
  27. {
  28.     long result;
  29.     static short level;    /* re-entrancy count */
  30.     
  31.         /*  set up A4  */
  32.  
  33.     asm {
  34.         move.l    a4,-(sp)
  35.         movea.l    a0,a4
  36.     }
  37.     
  38.         /*  respond to message  */
  39.  
  40.     ++level;
  41.     if (msg == macDev)
  42.         result = Runnable();
  43.     else {
  44.         if (msg == initDev) {
  45.             if (value = New()) {
  46.                 value->dp = dp;
  47.                 value->refnum = dp->windowKind;
  48.                 value->rsrcID = id;
  49.                 value->lastItem = nitems;
  50.             }
  51.         }
  52.         if (result = (long) value) {
  53.             value->event = event;
  54.             result = value->Message(msg, item);
  55.         }
  56.     }
  57.     --level;
  58.     
  59.         /*  restore A4  */
  60.  
  61.     asm {
  62.         move.l    a4,d0
  63.         beq.s    @1
  64.     }
  65.     if (!level)
  66.         UnloadA4Seg(0L);
  67.     asm {
  68. @1        movea.l    (sp)+,a4
  69.     }
  70.     return(result);
  71. }
  72.  
  73.  
  74. /*
  75.  *  cdev::Message - respond to message
  76.  *
  77.  *  The message is dispatched to the appropriate handler.
  78.  *
  79.  *  Few subclasses will need to override this method.
  80.  *
  81.  */
  82.  
  83. long
  84. cdev::Message(short msg, short item)
  85. {
  86.     long result;
  87.     
  88.     switch (msg) {
  89.         case initDev:
  90.             Init();
  91.             break;
  92.         case hitDev:
  93.             ItemHit(item - lastItem);
  94.             break;
  95.         case closeDev:
  96.             status = 0;
  97.             break;
  98.         case nulDev:
  99.             Idle();
  100.             break;
  101.         case updateDev:
  102.             Update();
  103.             break;
  104.         case activDev:
  105.             Activate();
  106.             break;
  107.         case deactivDev:
  108.             Deactivate();
  109.             break;
  110.         case keyEvtDev:
  111.             if (!(event->modifiers & cmdKey))
  112.                 Key((unsigned char) event->message);
  113.             else if (event->message != autoKey)
  114.                 CmdKey((unsigned char) event->message);
  115.             break;
  116.         case undoDev:
  117.             Undo();
  118.             break;
  119.         case cutDev:
  120.             Cut();
  121.             break;
  122.         case copyDev:
  123.             Copy();
  124.             break;
  125.         case pasteDev:
  126.             Paste();
  127.             break;
  128.         case clearDev:
  129.             Clear();
  130.             break;
  131.     }
  132.     if ((result = status) != (long) this)
  133.         Close();
  134.     return(result);
  135. }
  136.  
  137.  
  138. /*
  139.  *  cdev::Error - signal error
  140.  *
  141.  *  A typical call might be "Error(cdevResErr)".
  142.  *
  143.  *  Few subclasses will need to override this method.
  144.  *
  145.  */
  146.  
  147. void
  148. cdev::Error(long code)
  149. {
  150.     status = code;
  151. }
  152.  
  153.  
  154. /*
  155.  *  cdev::Init - handle "initDev" message
  156.  *
  157.  *  Subclasses overriding this method should call "inherited::Init()".
  158.  *
  159.  */
  160.  
  161. void
  162. cdev::Init()
  163. {
  164.     status = (long) this;
  165. }
  166.  
  167.  
  168. /*
  169.  *  cdev::Close - handle "closeDev" message
  170.  *
  171.  *  Subclasses overriding this method should call "inherited::Close()".
  172.  *
  173.  */
  174.  
  175. void
  176. cdev::Close()
  177. {
  178.     delete(this);
  179. }
  180.  
  181.  
  182. /*
  183.  *  cdev::CmdKey - process "keyEvtDev" (command key depressed)
  184.  *
  185.  *  Subclasses overriding this method should call "inherited::CmdKey(c)"
  186.  *  if the command key is not recognized.
  187.  *
  188.  */
  189.  
  190. void
  191. cdev::CmdKey(short c)
  192. {
  193.     switch (c) {
  194.         case 'z': case 'Z':
  195.             Undo();
  196.             break;
  197.         case 'x': case 'X':
  198.             Cut();
  199.             break;
  200.         case 'c': case 'C':
  201.             Copy();
  202.             break;
  203.         case 'v': case 'V':
  204.             Paste();
  205.             break;
  206.     }
  207. }
  208.  
  209.  
  210. /*
  211.  *  null methods
  212.  *
  213.  *  The remainder of the methods in this file are stubs.  Subclasses
  214.  *  may choose to implement appropriate behavior.
  215.  *
  216.  */
  217.  
  218. void
  219. cdev::Activate()
  220. {
  221. }
  222.  
  223.  
  224. void
  225. cdev::Update()
  226. {
  227. }
  228.  
  229.  
  230. void
  231. cdev::Idle()
  232. {
  233. }
  234.  
  235.  
  236. void
  237. cdev::ItemHit(short item)
  238. {
  239. }
  240.  
  241.  
  242. void
  243. cdev::Key(short c)
  244. {
  245. }
  246.  
  247.  
  248. void
  249. cdev::Deactivate()
  250. {
  251. }
  252.  
  253.  
  254. void
  255. cdev::Undo()
  256. {
  257. }
  258.  
  259.  
  260. void
  261. cdev::Cut()
  262. {
  263. }
  264.  
  265.  
  266. void
  267. cdev::Copy()
  268. {
  269. }
  270.  
  271.  
  272. void
  273. cdev::Paste()
  274. {
  275. }
  276.  
  277.  
  278. void
  279. cdev::Clear()
  280. {
  281. }
  282.